﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DELVE_GAME.ViewStructure.MapEditor
{
    class MapDrawer : ViewComponent
    {
        Map map;
        Sprite tileSprites;
        MapEditorCell[][] cells;

        public MapDrawer(Map map, Sprite tileSprites)
        {
            this.map = map;
            this.tileSprites = tileSprites;
            updateMap();
        }

        public override void draw(Microsoft.Xna.Framework.Graphics.SpriteBatch sb)
        {
            foreach (MapEditorCell[] ca in cells)
            {
                foreach (MapEditorCell c in ca)
                {
                    c.draw(sb);
                }
            }
        }

        internal void updateMap()
        {
            Tile[][] tiles = map.board;
            cells = new MapEditorCell[map.board.Length][];

            for (int i = 0; i < tiles.Length; i++)
            {
                Tile[] ta = tiles[i];
                cells[i] = new MapEditorCell[ta.Length];
                for (int j = 0; j < ta.Length; j++)
                {
                    cells[i][(ta.Length - 1) - j] = new MapEditorCell(ta[(ta.Length - 1) - j], i, j, tileSprites, offsetX, offsetY, map);
                }
            }
        }

        public override void mouseOver(int x, int y)
        {
            //base.mouseOver(x, y);
        }

        public override void keyPressed(Microsoft.Xna.Framework.Input.Keys key)
        {
            //base.keyPressed(key);
        }

        public override void keyReleased(Microsoft.Xna.Framework.Input.Keys key)
        {
            //base.keyReleased(key);
        }

        public override void mousePressed(int x, int y)
        {
            //base.mousePressed(x, y);
        }

        public override void mouseReleased(int x, int y)
        {
            //base.mouseReleased(x, y);
        }

        //override 

        internal MapEditorCell[][] getCells()
        {
            return cells;
        }
    }
}
